# Create distance matrices and datasets for matching

library(here)

source(here("Design", "nonbimatchingfunctions.R"))

load(here("Data", "wrkdatOwnMap_new.rda"), verbose = TRUE)

## from survey.geo.merge.R
##
##
## survey.geo$DAOtherAsian<-c(survey.geo$DACOL10+survey.geo$DACOL12+
##                              + survey.geo$DACOL14+survey.geo$DACOL15+survey.geo$DACOL16)/survey.geo$DACOL04
## survey.geo$DAChinese<-survey.geo$DACOL07/survey.geo$DACOL04
## survey.geo$DABlack<-survey.geo$DACOL09/survey.geo$DACOL04
## survey.geo$DALatin<-survey.geo$DACOL11/survey.geo$DACOL04
## survey.geo$DASouthAsian<-survey.geo$DACOL08/survey.geo$DACOL04
##
## survey.geo$da_diversity_index.da <- survey.geo$DAOtherAsian^2 +
##   survey.geo$DAChinese^2 +
##   survey.geo$DABlack^2 +
##   survey.geo$DALatin^2 +
##   survey.geo$DASouthAsian^2
##
## summary(survey.geo$da_diversity_index)



## Make simple objective distance
divdaDist <- scalar.dist(wrkdatOwnMap_new$da_diversity_index, scalefactor = 100000) ## the matching software wants integers
dimnames(divdaDist) <- list(row.names(wrkdatOwnMap_new), row.names(wrkdatOwnMap_new))

save(divdaDist, file = here("Design", "dist_mats_anyDA_Diversity_new.rda"))

# system("touch dist_mats_data_anyDA_new.done")
